using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QLNhaSach.BUS.DTO;

namespace QLNhaSach.DAO
{
    class NhanVienBanSachDAO:NhanVienDAO 
    {
        //Lay danh sach sach cua mot hoa don
        public static DataTable LaySachTrongHoaDon(int maHD)
        {
            string sql = "SELECT * FROM ((CTHoaDon cthd INNER JOIN HoaDon hd ON ";
            sql += " cthd.MaHD = hd.MaHD) INNER JOIN Sach s ON cthd.MaSach = s.MaSach) ";
            sql += " WHERE (hd.MaHD = " + maHD + ")";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        //Xoa mot dong trong chi tiet hoa don
        public static bool XoaChiTietHD(ChiTietHoaDonDTO cthd)
        {
            try
            {
                string sql = "DELETE FROM CTHoaDon WHERE (MaHD = " + cthd.MaHD + ") ";
                sql += " AND (MaSach = " + cthd.MaSach + ")";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        //Cap nhap tong tien cua hoa don
        public static bool CapNhapTongTien(HoaDonDTO hd)
        {
            try
            {
                string sql = "UPDATE HoaDon SET TongTien = " + hd.TongTien + " WHERE (MaHD = " + hd.MaHD + ")";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
